require('./src/utils/argv')

var Koa = require('koa');
var cors = require('@koa/cors');
var Router = require('koa-router');
const BodyParser = require('koa-bodyparser');

const bodyparser = new BodyParser();

var logController = require('./src/controller/log.controller')
var trackingController = require('./src/controller/tracking.controller')
var globalMiddleware = require('./src/middleware/global')
var log = require('./src/utils/log')
var auth = require('./src/middleware/auth')

var app = new Koa();
var router = new Router();

// 全局中间件
app.use(cors())
app.use(globalMiddleware.errorHandler)
app.use(globalMiddleware.anomalies)
app.use(log)
app.use(bodyparser)

router.get('/log/upload', logController.upload);
router.post('/sa/transapp', trackingController.transfer);

app.use(router.routes()).use(router.allowedMethods());

app.listen(_args.koaport);